package framework.eea.util;

import java.io.Serializable;

/**
 *
 * @author Markus Schr&ouml;der
 */
public class Timer implements Serializable {

    private int max;
    private long begin;
    private long current;
    private boolean updateable;
    
    public Timer(int max) {
        this.max = max;
        this.current = 0;
        begin();
       
    }
    
    public Timer(int max, boolean updateable) {
        this(max);
        this.updateable = updateable;
    }
    
    public boolean check() {
        if(((updateable ? current : System.currentTimeMillis()) - begin) > max) {
            begin();
            return true;
        }
        return false;
    }
    
    public void update(int delta) {
        if(updateable) {
            current += delta;
        }
    }
    
    public final void begin() {
        if(!updateable)
            begin = System.currentTimeMillis();
        else
            begin = current;
    }
    
}
